package com.ccubee.data.transfer.transfer;

import com.ccubee.data.transfer.transfer.mod.Imod;
import com.ccubee.data.transfer.types.TransferMod;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 数据上下文
 *
 * @Author ycf
 * @Date 2022/11/14 14:41
 * @Version 1.0
 */
@Component
public class TransferContext implements ApplicationContextAware {
    private final static Map<TransferMod, Imod> MOD_IMOD_MAP = new HashMap<>(2);

    public static Imod get(TransferMod mod) {
        return MOD_IMOD_MAP.get(mod);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        applicationContext.getBeansOfType(Imod.class).forEach((k, v) -> MOD_IMOD_MAP.put(v.mod(), v));
    }
}
